<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
    <el-form-item :label="$t('employing_company')" prop="employerId">
        <employerSelect v-model="queryParams.employerId"></employerSelect>
      </el-form-item>
      <el-form-item :label="$t('approval_workflow_name')" prop="approvalName">
        <el-input
          v-model="queryParams.approvalName"
          :placeholder="$t('please_enter',{name:$t('please_enter',{name:''})})"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('approval_event')" prop="incident">
        <el-select
          v-model="queryParams.incident"
          :placeholder="$t('please_select',{name:$t('approval_event')})"
          clearable
        >
          <el-option
            v-for="dict in dict.type.approval_event"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >{{$t('search')}}</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >{{$t('reset')}}</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['employer:approvalWay:add']"
          >{{$t('add')}}</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <approvalWay :loading="loading" :tableData="scheduleList">
      <el-table-column
        :label="$t('action')"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['employer:approvalWay:view']"
            >{{$t('view')}}</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['employer:approvalWay:edit']"
            >{{$t('edit')}}</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['employer:approvalWay:delete']"
            >{{$t('delete')}}</el-button
          >
        </template>
      </el-table-column>
    </approvalWay>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      :page-sizes="[10,20,30,50,100, 200]"
    />
    <!-- 添加或修改假期对话框 -->
    <AddOrUpdata
      ref="personDetail"
      @handleSuccess="handleSuccess"
    ></AddOrUpdata>
  </div>
</template>

<script>
import { processList, approvalprocessdel } from "@/api/custom/employerList";

import approvalWay from "@/views/custom/approvalWay/approvalWayTable.vue";
import AddOrUpdata from "@/views/custom/approvalWay/addOrUpdata.vue";
import employerSelect from "@/views/components/custom/employerSelect.vue";
export default {
  name: "Schedule",
  dicts: ["approval_event"],
  components: {
    approvalWay,
    AddOrUpdata,
    employerSelect
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 假期表格数据
      scheduleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        queryParams: "",
        approvalName: "",
        employerName:"",
        employerId:null,
      },

      needInfo: {},

      annualLeave: [
        {
          lengthService: null,
          vacation: null,
        },
      ],
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询假期列表 */
    getList() {
      this.loading = true;
      processList(this.queryParams).then((response) => {
        this.scheduleList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    handleSuccess() {
      this.getList();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.lookView = false;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      // this.open = true;
      // this.title = "添加假期";
      let detailParams = {
        item: {},
        title: this.$t('add'),
        lookView: false,
      };
      this.$refs.personDetail.showDateschedule(detailParams);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      let detailParams = {
        item: row,
        title:this.$t('edit'),
        lookView: false,
      };
      this.$refs.personDetail.showDateschedule(detailParams);
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      let detailParams = {
        item: row,
        title: this.$t('view'),
        lookView: true,
      };
      this.$refs.personDetail.showDateschedule(detailParams);
    },
    /** 提交按钮 */
    // submitForm() {
    //   this.$refs["form"].validate((valid) => {
    //     if (valid) {
    //       if (this.form.libertyDay) {
    //         this.form.libertyDay = this.form.libertyDay.join(",");
    //       }
    //       if (this.form.sabbaticalDay) {
    //         this.form.sabbaticalDay = this.form.sabbaticalDay.join(",");
    //       }

    //       if (this.form.id != null) {
    //         updateSchedule(this.form).then((response) => {
    //           this.$modal.msgSuccess("修改成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       } else {
    //         addSchedule(this.form).then((response) => {
    //           this.$modal.msgSuccess("新增成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       }
    //     }
    //   });
    // },
    // /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id;
      this.$modal
        .confirm(this.$t('delete_data'))
        .then(function () {
          return approvalprocessdel(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess(this.$t('operation_successful'));
        })
        .catch(() => {});
    },
    // /** 导出按钮操作 */
    // handleExport() {
    //   this.download(
    //     "schedule/schedule/export", {
    //       ...this.queryParams,
    //     },
    //     `schedule_${new Date().getTime()}.xlsx`
    //   );
    // },
    // /** 导入按钮操作 */
    // handleImport() {
    //   this.$refs.importModal.showModal();
    // },
    // handleAddAnnualLeave() {
    //   this.annualLeave.push({
    //     lengthService: null,
    //     vacation: null,
    //   });
    // },
    // handleDeleteAnnualLeave(index) {
    //   this.annualLeave.splice(index, 1)
    // }
  },
};
</script>
